﻿/**
* jQuery EasyUI 1.2.2
* 
* Licensed under the GPL:
*   http://www.gnu.org/licenses/gpl.txt
*
* Copyright 2010 stworthy [ stworthy@gmail.com ] 
* 
*/
(function ($) {
    function _1(_2) {
        var _3 = $.data(_2, "datebox");
        var _4 = _3.options;
        $(_2).combo($.extend({}, _4, { onShowPanel: function () {
            _3.calendar.calendar("resize");
            _4.onShowPanel.call(_2);
        } 
        }));
        $(_2).combo("textbox").parent().addClass("datebox");
        if (!_3.calendar) {
            _5();
        }
        function _5() {
            var _6 = $(_2).combo("panel");
            _3.calendar = $("<div></div>").appendTo(_6).wrap("<div class=\"datebox-calendar-inner\"></div>");
            _3.calendar.calendar({ fit: true, border: false, onSelect: function (_7) {
                var _8 = _4.formatter(_7);
                _c(_2, _8);
                $(_2).combo("hidePanel");
                _4.onSelect.call(_2, _7);
            } 
            });
            _c(_2, _4.value);
            var _9 = $("<div class=\"datebox-button\"></div>").appendTo(_6);
            $("<a href=\"javascript:void(0)\" class=\"datebox-current\"></a>").html(_4.currentText).appendTo(_9);
            $("<a href=\"javascript:void(0)\" class=\"datebox-close\"></a>").html(_4.closeText).appendTo(_9);
            _9.find(".datebox-current,.datebox-close").hover(function () {
                $(this).addClass("datebox-button-hover");
            }, function () {
                $(this).removeClass("datebox-button-hover");
            });
            _9.find(".datebox-current").click(function () {
                _3.calendar.calendar({ year: new Date().getFullYear(), month: new Date().getMonth() + 1, current: new Date() });
            });
            _9.find(".datebox-close").click(function () {
                $(_2).combo("hidePanel");
            });
        };
    };
    function _a(_b, q) {
        _c(_b, q);
    };
    function _d(_e) {
        var _f = $.data(_e, "datebox").options;
        var c = $.data(_e, "datebox").calendar;
        var _10 = _f.formatter(c.calendar("options").current);
        _c(_e, _10);
        $(_e).combo("hidePanel");
    };
    function _c(_11, _12) {
        var _13 = $.data(_11, "datebox");
        var _14 = _13.options;
        $(_11).combo("setValue", _12).combo("setText", _12);
        _13.calendar.calendar("moveTo", _14.parser(_12));
    };
    $.fn.datebox = function (_15, _16) {
        if (typeof _15 == "string") {
            var _17 = $.fn.datebox.methods[_15];
            if (_17) {
                return _17(this, _16);
            } else {
                return this.combo(_15, _16);
            }
        }
        _15 = _15 || {};
        return this.each(function () {
            var _18 = $.data(this, "datebox");
            if (_18) {
                $.extend(_18.options, _15);
            } else {
                $.data(this, "datebox", { options: $.extend({}, $.fn.datebox.defaults, $.fn.datebox.parseOptions(this), _15) });
            }
            _1(this);
        });
    };
    $.fn.datebox.methods = { options: function (jq) {
        return $.data(jq[0], "datebox").options;
    }, calendar: function (jq) {
        return $.data(jq[0], "datebox").calendar;
    }, setValue: function (jq, _19) {
        return jq.each(function () {
            _c(this, _19);
        });
    } 
    };
    $.fn.datebox.parseOptions = function (_1a) {
        var t = $(_1a);
        return $.extend({}, $.fn.combo.parseOptions(_1a), {});
    };
    $.fn.datebox.defaults = $.extend({}, $.fn.combo.defaults, { panelWidth: 180, panelHeight: "auto", keyHandler: { up: function () {
    }, down: function () {
    }, enter: function () {
        _d(this);
    }, query: function (q) {
        _a(this, q);
    } 
    }, currentText: "Today", closeText: "Close", okText: "Ok", formatter: function (_1b) {
        var y = _1b.getFullYear();
        var m = _1b.getMonth() + 1;
        var d = _1b.getDate();
        return m + "/" + d + "/" + y;
    }, parser: function (s) {
        var t = Date.parse(s);
        if (!isNaN(t)) {
            return new Date(t);
        } else {
            return new Date();
        }
    }, onSelect: function (_1c) {
    } 
    });
})(jQuery);

